<?php

/*
  Action	$4

  +1$

  When you play this card, you may immediatly play treasures and  buy 1 card. If you do, put it in your hand

 */

class DigitalStore extends Card implements iAction, iKingdom, iAddiction {

    public function __construct() {
        parent::__construct("Digital Store", 4);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }
    
    public function isImplemented() {
        return false;
    }

    public function getDescription() {
        return array(
            "+1$",
            "When you play this card, you may immediatly play treasures and  buy 1 card. If you do, put it in your hand");
    }

    public function play(Game $game, $isRealCard) {
        $game->addMoney(new Price(1));
        ScreenDisplay::addScreenMessage($game, true, "get +1$", "gets +1$");
        $cards = $game->getBoardCardsByPrice();
        $options = array();
        foreach ($cards as $card) {
            $options[] = $card;
        }
        $options[] = new Option(1, 'None');
        $output = MySocket::GetUserReplyBuyBeforeAction("DigitalStore", $game, Input_ChooseOne, $options, 1, 1, null, "Choose card to buy", null, true);
    }

    public function buyCard(Game $game, $card_name) {

        $game->setPhase(Phase_DigitalStoreBuy);
        $game->addBuys(1);
        $cards = array();
        if ($card_name == 'None') {
            $game->addBuys(-1);
            ScreenDisplay::addScreenMessage($game, true, "buy nothing", "buys nothing");
        } else {
            $newcard = $game->buy($card_name);
            if ($newcard) {
                $game->moveCardFromPileToPile($newcard, DiscardPile, PlayHand);
            } else {
                $game->addBuys(-1);
                ScreenDisplay::addScreenMessage($game, true, "can't buy " . nicePrint($card_name) . " - not enough money");

                $cards = $game->getBoardCardsByPrice();
                $options = array();
                foreach ($cards as $card) {
                    $options[] = $card;
                }
                $options[] = new Option(1, 'None');
                $output = MySocket::GetUserReplyBuyBeforeAction("DigitalStore", $game, Input_ChooseOne, $options, 1, 1, null, "Choose card to buy", null, true);
                return;
            }
        }
        $game->cardActionFinished();
    }

}

?>